package com.zhangjg.database;
 
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import javax.sql.DataSource;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
 
 
public class DBManager {
 
    public static Log log = LogFactory.getLog(SuperDao.class);
    private static DataSource ds = null;   
     
    static {
    	try {
    		if(ds==null){
    			InputStream in = DBManager.class.getClassLoader().getResourceAsStream("druid.properties");
    			Properties props = new Properties();
    			props.load(in);
    			ds = DruidDataSourceFactory.createDataSource(props);
    		}
    	} catch (Exception e) {
    	    log.error(e.getMessage());
    	}
    }
     
    public static Connection getConnection(){
    	try {
            return ds.getConnection();
        } catch (SQLException e) {
            log.error(e.getMessage());
            return null;
        }
    } 
    
    /**连接类型枚举*/
    protected static enum DbRelatedDs{
      CON, DS;
    }
     
}